<template>
  <div class="apply-card-list">
    <div class="card" v-for="(v, k) in cardList" :key="k" @click="routeToDetail(v.id)">
      <img class="image" :src="v.card_image" alt="银行卡">
      <div class="section">
        <div class="title">{{v.card_name}}</div>
        <div class="desc">{{v.owners}}人拥有</div>
        <div class="desc">{{v.brief_introduction}}</div>
      </div>
      <mt-button class="apply-btn" @click.native="routeTo(v.link, $event)">立即申请</mt-button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ApplyCard',
  data () {
    return {
      cardList: []
    }
  },
  methods: {
    routeTo (url, event) {
      event.cancelBubble = true
      this.$router.push({path: url})
    },
    routeToDetail (id) {
      this.$router.push({name: 'BankCard', params: {id: id}})
    }
  },
  mounted () {
    let id = this.$route.params.id
    let type = this.$route.params.type
    let params = {}
    switch (type) {
      case 'bank':
        params.bank_id = id
        this.$post('/vue/request_card/get_list_by_bank_id', params, true).then(data => {
          this.cardList = data.act_list
        })
        break
      case 'tags':
        params.tag_id = id
        this.$post('/vue/request_card/get_cards_by_tag', params, true).then(data => {
          this.cardList = data.act_list
        })
        break
    }
  }
}
</script>

<style lang="less">
@c-lanse: rgb(108, 184, 222);
@c-124: rgb(124, 124, 124);
@c-169: rgb(169, 169, 169);
@bc-235: rgb(235, 235, 235);
.flex {
  display: flex;
  align-items: center;
  align-content: flex-start;
  justify-content: space-between;
}
.apply-card-list {
  width: 100%;
  min-height: 100vh;
  background-color: #FFF;
  .card {
    &:extend(.flex);
    margin-left: 12px;
    padding: 12px 12px 12px 0;
    border-bottom: 1px solid @bc-235;
    background-color: #FFF;
    .image {
      flex: 0 0 auto;
      width: 34%;
      display: block;
      height: 72px;
    }
    .section {
      margin: 0 3%;
      text-align: left;
      flex: 0 0 37%;
      .title {
        color: @c-124;
        font-size: 15px;
        font-weight: bold;
        line-height: 24px;
      }
      .desc {
        color: @c-169;
        font-size: 12px;
        line-height: 20px;
        width: 34vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
    .apply-btn {
      flex: 0 0 23%;
      width: auto;
      height: 32px;
      border: 2px solid @c-lanse;
      border-radius: 16px;
      font-size: 13px;
      line-height: 24px;
      color: @c-lanse;
      background: transparent;
    }
  }
}
</style>
